/*
 Rainbowduino_NooTe v3.0 Library. 
 
 2011 Copyright (c) Seeed Technology Inc.
 
 Authors: Albert.Miao, Visweswara R

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

/*
This library heavily makes use of line, circle and other shape drawing algorithms and code presented
in paper "The Beauty of Bresenham's Algorithm" by Alois Zingl, Vienna, Austria. The original author
has kindly released these example programs with no copyright.
*/

#ifndef RAINBOWDUINO_h
#define RAINBOWDUINO_h

#include <Arduino.h>
#include <avr/pgmspace.h>


// MY9221 driver interfaces 

#define DDR_Data  DDRB
#define DDR_Clk   DDRB

#define PORT_Data PORTB
#define PORT_Clk  PORTB

#define BIT_Data  0x01
#define BIT_Clk   0x02

// 3-to-8 Decoder Lines

#define DDR_Lines  DDRD
#define PORT_Lines PORTD
#define BIT_Lines  0xF0
#define switchOffDrive	{PORT_Lines &=~ 0x80;}

#define CmdMode 0b0000000000000000

#define BLACK 0x000000
#define WHITE 0xFFFFFF
#define SILVER 0xC0C0C0
#define GRAY 0x808080

#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
#define AQUA 0x00FFFF
#define YELLOW 0xFFFF00
#define FUSHIA 0xFF00FF

class Rainbowduino_NooTe
{
public:
    void init();
    void init_timer1(void);
    
	void send16bitData(uint32_t data);
    void latchData(void);
    void switchOnDrive(uint8_t line);
    
	void clearDisplay(void); //Is not made private method as used in ISR. Use this like a private method.
    void blankDisplay(void);
	
	uint32_t makeColor(uint8_t red, uint8_t green, uint8_t blue);
	
    void drawPixel(int16_t x, int16_t y, uint32_t colorRGB);
    void drawCircle(int16_t poX, int16_t poY, uint16_t r, uint32_t colorRGB);
    void fillCircle(int16_t poX, int16_t poY, uint16_t r, uint32_t colorRGB);
    void drawLine(int16_t x0,int16_t y0, int16_t x1, int16_t y1, uint32_t colorRGB);
    void drawVerticalLine(int16_t poX, int16_t poY, uint16_t length, uint32_t colorRGB);
    void drawHorizontalLine(int16_t poX, int16_t poY, uint16_t length, uint32_t colorRGB);
    void drawRectangle(int16_t poX, int16_t poY, uint16_t length, uint16_t width, uint32_t colorRGB);
    void fillRectangle(int16_t poX, int16_t poY, uint16_t length, uint16_t width, uint32_t colorRGB);
	void drawSquare(int16_t poX, int16_t poY, uint16_t length, uint32_t colorRGB);
	void fillSquare(int16_t poX, int16_t poY, uint16_t length, uint32_t colorRGB);
	void fill(uint32_t colorRGB);
	
    void drawChar(int16_t poX, int16_t poY, uint8_t ascii, uint32_t colorRGB);

private:

};

extern Rainbowduino_NooTe Rb;

#endif
